$package('itsm.news');

itsm.news.newsMain=function(){
	this.opt='';
	return {
		//列表
		newsMainGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'news!findNewsPager.action?newsQueryDTO.newType='+newsMain_newType,
				caption:'内容列表',
				colNames:['ID','分类','内容标题','关键字','是否置顶','发布时间','最后修改时间','发布人'],
			 	colModel:[
			 	          {name:'newId',align:'center'},
			 	          {name:'categoryName',align:'left',hidden:true},
			 	          {name:'title',align:'left'},
			 	          {name:'keyword',align:'left'},
			 	          {name:'top',align:'center'},
			 	          {name:'createTime',align:'left'},
			 	          {name:'lastUpdateTime',align:'left'},
			 	          {name:'releaseUser',align:'left'}
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "newId"}),
				sortname:'newId',
				pager:'#newsMainPager',
				ondblClickRow:function(rowId){
						itsm.news.newsMain.newsDetails(rowId)
					},
				});
				$("#newsMainGrid").jqGrid(params);
				$("#newsMainGrid").navGrid('#newsMainPager',navGridParams);
				//列表操作项
				$("#t_newsMainGrid").css(jqGridTopStyles);
				$("#t_newsMainGrid").html($('#newsMainGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#newsMainGrid","regCenter",10);
		},
		//打开添加窗口
		openAddWin:function(){
			itsm.common.utility.tabUtility.refreshTab('新增内容','news/addNews.jsp')
		},
		
		//打开编辑窗口
		openEditWin:function(){
			opt='editnews';
			checkBeforeEditGrid('#newsMainGrid',function(rowData){
				itsm.common.utility.tabUtility.refreshTab('编辑内容','news!findNewsById.action?newsQueryDTO.newId='+rowData.newId);
			});	
		},
		
		
		//删除
		deleteNews:function(){
			checkBeforeDeleteGrid('#newsMainGrid',function(rowIds){
				var pp = $.param({'ids':rowIds},true);
				$.post("news!deleteNews.action", pp, function(){
					$('#newsMainGrid').trigger('reloadGrid');
					msgShow('删除成功!','show');
					
				}, "json");
			});
		},
		//打开搜索窗口
		openSearchWin:function(){
			$('#newsMain_search_win').window('open');
		},
		//搜索
		searchnews:function(){
			var sdata=$('#newsMain_search_win form').getForm();
			var postData = $("#newsMainGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'news!findnewsPager.action';	
			$('#newsMainGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		newsDetails:function(newId){
			itsm.common.utility.tabUtility.reOpenTab('news/newsDetail.jsp?newId='+newId,'内容详细')
		},
		
		init:function(){
			itsm.news.newsMain.newsMainGrid();
		}
	}
	
}();

$(function(){
	itsm.news.newsMain.init();
});